package cn.itcast.order.service;

import cn.itcast.order.clients.UserClient;
import cn.itcast.order.mapper.OrderMapper;
import cn.itcast.order.pojo.Order;
import cn.itcast.order.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class OrderService {

    @Autowired
    private OrderMapper orderMapper;

    @Autowired
    private UserClient userClient;

    public Order queryOrderById(Long orderId) {
        // 1.查询订单
        Order order = orderMapper.findById(orderId);

        User user=userClient.findById(order.getUserId());

        //3.封装User消息
        order.setUser(user);

        // 4.返回
        return order;
    }

//    @Autowired
//    private RestTemplate restTemplate;

//    public Order queryOrderById(Long orderId) {
//        // 1.查询订单
//        Order order = orderMapper.findById(orderId);
//
//        //2.查询用户  直接用服务名替代ip和端口号
//        String url="http://userService/user/"+order.getUserId();
//        User user=restTemplate.getForObject(url,User.class);
//
//        //3.封装User消息
//        order.setUser(user);
//
//        // 4.返回
//        return order;
//    }

}
